#include<bits/stdc++.h>
using namespace std;
const int maxn=10010;
int r[maxn];
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    freopen("duel.in","r",stdin);
    freopen("duel.out","w",stdout);
    long long n;
    cin>>n;
    int maxl=0;
    for(int i=1;i<=n;i++){
        cin>>r[i];
        maxl=max(maxl,r[i]);
    }
    for(int i=1;i<=n;i++)
        for(int j=i+1;j<=n;j++)
            if(r[i]<r[j])
                swap(r[i],r[j]);
    if(maxl==2){
        int a1=0,a2=0;
        for(int i=1;i<=n;i++)
            if(r[i]==1)
                a1++;
        cout<<a1<<endl;
    }else{
        int i=n-1,j=n;
        while(i>=1){
            if(r[i]>r[j])
                j--;
            i--;
        }
    cout<<j<<endl;
    }

    return 0;
}
